import time
import asyncio


async def run(i):
    print("开启协程",i)
    await asyncio.sleep(2)
    print("结束任务", i)



if __name__ == '__main__':
    task_list = []
    for i in range(1, 5):
        c = run(i)
        task = asyncio.ensure_future(c)
        task_list.append(task)
    print(task_list)
    event_loop = asyncio.get_event_loop()
    # 使用asyncio.wait(task_list)把多任务的列表注册到事件循环中
    event_loop.run_until_complete(asyncio.wait(task_list))